#!/usr/env/bin python
# -*- coding: utf-8 -*-

# @Time    : 2020/8/9 11:07|11:07
# @Author  : yangdingyi
# @File    : 2020-08-09.2.5484.找出第N个二进制字符串中的第K位
# @Software: PyCharm
from tools.my_methods import *


class Solution:
    def findKthBit(self, n: int, k: int) -> str:
        ans = ''
        num = '0'

        def reverse(nn):
            nnn = list(nn)
            nnn.reverse()
            return ''.join(nnn)

        def invert(nn):
            nnn = ''.join(list(map(lambda x: '0' if x == '1' else '1', nn)))
            return nnn

        while n > 1:
            num = num + '1' + reverse(invert(num))
            n -= 1

        ans = num[k-1]
        return ans


questions = [
    (1, 1),
    (2, 3),
]

work(questions, lambda q: Solution().findKthBit(q[0], q[1]))
